'''
使用类实现迭代器，实现斐波拉契数列
'''
class rabbit():
    j=0
    i=1
    def r(self):
        while True:
            yield self.i
            self.j,self.i=self.i,self.i + self.j
s=rabbit().r()
for h in range(10):
    print(s.__next__(),end=' ')
print('\n')

'''
使用面向对象做一个ATM（存取款功能）
ATM类
 属性： 钱，区域
 方法：（存取）
     用户可以过来取钱
     取了钱ATM的钱就会减少
     用户的账户的钱也会减少
用户类
 属性：用户名，  密码， 账户金额
要求：
   菜单   有登陆验证
'''
class ATM():
    money=500000
    area='长沙'
    atmuser={"root":'123456',"admin":'123456'}
    def add_user(self,name,passwd):
        if name in self.atmuser:
            print("该用户名已存在")
            return False
        else:
            self.atmuser[name]=passwd
            print("注册成功")
            return True
    def login(self,name,passwd):
        if name in self.atmuser and self.atmuser[name]==passwd:
            print("登陆成功")
            return True
        else:
            print("账号或密码错误")
            return False
    def save(self,savemoney):
        money=self.money
        self.money+=savemoney
        print(f"ATM初始金额金额为{money},已存{savemoney},现有金额{self.money}")
        return True
    def withdraw(self,withdrawmoney):
        if withdrawmoney>self.money:
            print("ATM余额不足 操作失败")
            return False
        else:
            money = self.money
            self.money -= withdrawmoney
            print(f"ATM初始金额金额为{money},已取{withdrawmoney},现有金额{self.money}")
            return True

class user():
    def __init__(self,name,passwd,money):
        self.username=name
        self.passwd=passwd
        self.money=money

    def save(self, savemoney):
        money1 = self.money
        self.money += savemoney
        print(f"您的初始金额金额为{money1},已存{savemoney},现有金额{self.money}")
        return True

    def withdraw(self, withdrawmoney):
        if withdrawmoney > self.money:
            print("您的余额不足 操作失败")
            return False
        else:
            money = self.money
            self.money -= withdrawmoney
            print(f"您的初始金额金额为{money},已取{withdrawmoney},现有金额{self.money}")
            return True
def save(atm,user0,save0):
    if atm.save(save0) and user0.save(save0):
        print("操作成功")
        return True
    else:
        print("操作失败")
        return False
def withdraw(atm,user0,withdrow):
    if atm.withdraw(withdrow) and user0.withdraw(withdrow):
        print("操作成功")
        return True
    else:
        print("操作失败")
        return False

sanchuang=ATM()
print(f"欢迎来到{sanchuang.area}三创银行")

while 1:
    print('''
    请选择登录或注册：
    1.已有帐号，进行登录
    2.注册
    ''')
    option0=int(input("请选择1或2:"))
    if option0==1:
        n1=input("请输入用户名:")
        p1=input("请输入密码:")
        if sanchuang.login(n1,p1):
            n=n1
            p=p1
            break
    if option0==2:
        n2 = input("请输入用户名:")
        p2 = input("请输入密码:")
        sanchuang.add_user(n2,p2)

print(f"{n},",end='')
m=int(input("请输入您账户的初始金额"))
user1=user(n,p,m)
while True:
    print('''
    请输入您要进行的操作：
    1.存钱
    2.取钱
    3.退出系统
    ''')
    option1=int(input())
    if option1==1:
        m1=int(input("请输入要存入的金额："))
        if save(sanchuang,user1,m1):
            print("手续已完成！")
        else:
            print("操作失败")
    elif option1==2:
        m2 = int(input("请输入要取出的金额："))
        if withdraw(sanchuang,user1,m2):
            print("手续已完成！")
        else:
            print("操作失败")
    elif option1==3:
        break
    else:
        print("输入不合法")
print("欢迎下次光临！！")
